// pages/agriculturalproject/agriculturalproject.js
const db = wx.cloud.database();
const app = getApp();
Page({
  /**
   * 页面的初始数据
   */
  data: {
    banner: [{
      id: 0,
      url: "cloud://cloud1-1ga8zsp16c57584a.636c-cloud1-1ga8zsp16c57584a-1308614351/project/topBanner.png"
    }],
    bannerGo: {
      project_id: "6d85a2b96288d02c05dff0572f0373f1",
      src: "cloud://cloud1-1ga8zsp16c57584a.636c-cloud1-1ga8zsp16c57584a-1308614351/image/projectBanner.png"
    },
    recommendProject: [],
    loading: true
  },


  bannerImageLoad(e) {
    console.log(e)
  },
  icon1Load(e) {
    console.log(e)
  },
  icon2Load(e) {
    console.log(e)
  },
  searchLoad(e) {
    console.log(e)
  },
  bannerGoLoad(e) {
    console.log(e)
  },

  navToAllProject() {
    wx.navigateTo({
      url: '/pages/allProject/allProject',
    })
  },
  navToCollectProject() {
    console.log("跳转到收藏项目")
    wx.navigateTo({
      url: '/pages/collectProject/collectProject',
    })
  },
  navToDetail(e) {
    console.log(e.currentTarget.dataset.project_detail);
    app.navTmpInfo = e.currentTarget.dataset.project_detail;
    wx.navigateTo({
      url: '/pages/project_detail/project_detail'
    })
  },
  gethome() {
    wx.navigateBack({
      delta: 1
    })
  },
  async navToBannerGoDetail() {
    await db.collection('projects').doc(this.data.bannerGo.project_id).get({
      success: res => {
        app.navTmpInfo = res.data;
        console.log(app.navTmpInfo);
        wx.navigateTo({
          url: '/pages/project_detail/project_detail',
        })
      }
    });
  },


  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

    let that = this;
    db.collection("projects").where({
      hot: true
    }).get({
      success: res => {
        console.log(res.data)
        that.setData({
          recommendProject: res.data
        })
      },
      complete: () => {
        that.setData({
          loading: false
        })
      }
    })
  },
  navToSearchProject() {
    wx.navigateTo({
      url: '/pages/searchProject/searchProject',
    })
  },


  // -------------------------------------------------------------------
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})